package acm.蓝桥23;

import java.util.Scanner;

public class B_特殊背包 {

	static int maxn=2010,maxm=10010;
	static int n,m,k;
	static int[] w,v;
	static int[][][]dp=new int[2][maxn][maxm];
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		m=sc.nextInt();
		k=sc.nextInt();
		w=new int[n+1];
		v=new int[n+1];
		for(int i=1;i<=n;i++) {
			w[i]=sc.nextInt();
			v[i]=sc.nextInt();
		}
		int res=dfs(n,m,1);
		System.out.println(res);
	}
	public static int dfs(int i,int sum,int isUse) {
		if(i<=0) {
			return 0;
		}
		if(dp[isUse][i][sum]!=0) {
			return dp[isUse][i][sum];
		}
		int nochose=dfs(i-1,sum,isUse);
		int chose=0;
		if(sum>=w[i]) {
			chose=dfs(i-1,sum-w[i],isUse)+v[i];
			if(isUse==1&&sum>=w[i]+k) {
				chose=Math.max(chose, dfs(i-1,sum-w[i]-k,0)+v[i]*2);
			}
		}
		dp[isUse][i][sum]= Math.max(chose, nochose);
		return dp[isUse][i][sum];
	}
	
}
